package com.blds.mc.util;

import org.apache.commons.net.ftp.FTPClient;

import java.io.IOException;
import java.io.InputStream;

public class FtpUtil {

    public  static String uploadFile(String originFileName, InputStream input){
        FTPClient ftpClient = new FTPClient();
        ftpClient.setControlEncoding("GBK");
        try {
            ftpClient.connect("39.105.58.0", 21);
            boolean login = ftpClient.login("bldsftp", "Tyj147258");
            if(!login) { return "登录失败";}
            ftpClient.enterLocalPassiveMode();
            ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
            ftpClient.changeWorkingDirectory("/var/ftp/bldsftp/" );
            boolean res = ftpClient.storeFile(originFileName, input);
            return res + "";
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                input.close();
                ftpClient.logout();
                ftpClient.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return "出现异常";
        }
    }
}
